import Cookies from "js-cookie";

const TokenKey = "weight_token";
const UserKey = "weight_user";

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token) {
  return Cookies.set(TokenKey, token);
}

export function getUser() {
  return Cookies.get(UserKey);
}

export function setUser(name) {
  return Cookies.set(UserKey, name);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export function fetch(STORAGE_KEY) {
  return JSON.parse(window.localStorage.getItem(STORAGE_KEY) || "{}");
}

export function save(STORAGE_KEY, items) {
  window.localStorage.setItem(STORAGE_KEY, JSON.stringify(items));
}
